#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#  Copyright (c) Huoty - All rights reserved
# 
#      Author: Huoty <sudohuoty@gmail.com>
#  CreateTime: 2016-10-25 14:40:04
# *************************************************************

import sys
import pip

from importlib import import_module
from importlib.abc import MetaPathFinder

class PipMetaPathFinder(MetaPathFinder):
    """A importlib.abc.MetaPathFinder to auto-install missing modules using pip
    """
    def find_spec(fullname, path, target=None):
        if path == None: 
            installed = pip.main(['install', fullname])
            if installed == 0:
                return import_module(fullname)

sys.meta_path.append(PipMetaPathFinder)

